interface Square {
    kind: "square";
    size: number;
}
interface Rectangle {
    kind: "rectangle";
    width: number;
    height: number;
}
interface Circle {
    kind: "circle";
    radius: number;
}

function assertNever(x: never): never {
    throw new Error("Unexpected object: " + x);
}
// 3个接口中 都有共有的键 kind 但是 该键的值 都不一样 
// 可以用这个字段类分辨是那个接口类型
type  Shape = Square | Rectangle | Circle

function area(s: Shape):number {
    switch (s.kind) {
        case "square": return s.size * s.size;
        case "rectangle": return s.height * s.width;
        // case "circle":return s.radius
        default: return assertNever(s); 
    }
}